<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title></title>
  </head>
  <body>
    <div id="app">
      <div>修改 beforeData1：<input type="text" v-model="beforeData1" /></div>
      <hr />
      <div>修改 beforeData2：<input type="text" v-model="beforeData2" /></div>
      <hr />
      <div>修改 afterData：<input type="text" v-model="afterData" /></div>
    </div>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
      const { createApp, ref, watchEffect } = Vue;

      createApp({
        setup() {
          const beforeData1 = ref("beforeData1");
          const beforeData2 = ref("beforeData2");
          const afterData = ref("afterData");

          // 必须第一个 await 前面的依赖才可以被
          // watchEffect 异步函数所搜集
          watchEffect(async () => {
            console.log("beforeData1.value", beforeData1.value);
            const response = await fetch("/");
            console.log("beforeData2.value", beforeData2.value);
            const response2 = await fetch("/");
            console.log("afterData.value", afterData.value);
            console.log("response", response);
            console.log("response2", response2);
            console.log("--- 分割线 ---");
          });
          return {
            beforeData1,
            beforeData2,
            afterData,
          };
        },
      }).mount("#app");
    </script>
  </body>
</html>
